<html class="login-alone">
<head>
    <title>熊大论坛 - 登录</title>

    <meta name="description" content="熊大论坛" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/style/blue/screen.css?v=3.9" media="screen, projection" rel="stylesheet" type="text/css" >

    <link rel="stylesheet" type="text/css" href="/style/blue/base.css?v=3.9">
    <link rel="stylesheet" type="text/css" href="/style/blue/login.css?v=3.9">
    <script type="text/javascript" src="/script/jquery.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#loginBtn").click(function(){
                let username = $("#username").val();
                let password = $("#password").val();
                //发送ajax请求
                $.post("/users/login",{
                    username:username,
                    password:password
                },function(rs){
                    if(rs.status =='200'){//登录成功
                        //把token保存到sessionStorage
                        sessionStorage.setItem("token",rs.token);
                        sessionStorage.setItem("username",rs.token);
                        // 存储token到cookie
                        document.cookie = "username=" + rs.token + ";path=/";
                        console.log(rs.token);
                        alert(rs.token)
                        //跳转到首页
                        location.href="/index?token="+rs.token;
                    }else{//登录失败
                        alert(rs.msg);
                        $("#username").val("");
                        $("#password").val("");
                    }
                },"json")

            });
        })
    </script>
</head>
<body>
<div class="logina-logo" style="height: 55px">
    <a href="#"><img src="/style/blue/images/logo_max.png" class="logoImg"/></a>
    <span class="logoText">熊大  买一本呗</span>
</div>
<div class="logina-main main clearfix">
    <div class="tab-con">
        <form id="form-login" method="post" action="">
            <div id='login-error' class="error-tip"></div>
            <table border="0" cellspacing="0" cellpadding="0">
                <tbody>
                <tr>
                    <th>用户名</th>
                    <td width="245">
                        <input id="username" type="text" name="username" placeholder="用户名" autocomplete="off" value=""></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <th>密码</th>
                    <td width="245">
                        <input id="password" type="password" name="password" placeholder="请输入密码" autocomplete="off">
                    </td>
                    <td>
                    </td>
                </tr>
                <tr class="find">
                    <th></th>
                    <td>
                        <div>
                            <label class="checkbox" for="chk11"><input style="height: auto;" id="chk11" type="checkbox" name="remember_me" >记住我</label>
                            <a href="#">忘记密码？</a>
                        </div>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <th></th>
                    <td width="245"><input class="confirm" type="button" id="loginBtn" value="登  录"></td>
                    <td></td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class="reg">
        <p>还没有账号？<br>赶快免费注册一个吧！</p>
        <a class="reg-btn" href="/register.html">立即免费注册</a>
    </div>
</div>
</body>
</html>
